"""
医院相关的 Pydantic 模型
"""
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime


class HospitalBase(BaseModel):
    """医院基础字段"""
    hospital_name: str = Field(..., min_length=1, max_length=200, description="医院名称")
    invite_code: str = Field(..., min_length=1, max_length=50, description="邀请码")


class HospitalCreate(HospitalBase):
    """创建医院"""
    pass


class HospitalUpdate(BaseModel):
    """更新医院"""
    hospital_name: Optional[str] = Field(None, min_length=1, max_length=200, description="医院名称")
    invite_code: Optional[str] = Field(None, min_length=1, max_length=50, description="邀请码")
    status: Optional[int] = Field(None, description="状态")


class HospitalResponse(HospitalBase):
    """医院响应"""
    id: int
    status: int
    created_at: datetime
    updated_at: datetime
    
    model_config = {
        "from_attributes": True
    }
    
    def to_flask_format(self):
        """转换为原 Flask 项目的响应格式"""
        return {
            "_id": str(self.id),
            "hospital_name": self.hospital_name,
            "invite_code": self.invite_code,
            "status": self.status,
            "created_at": self.created_at.isoformat() if self.created_at else None,
            "updated_at": self.updated_at.isoformat() if self.updated_at else None
        }


class ValidateCodeRequest(BaseModel):
    """验证邀请码请求"""
    hospital_name: str = Field(..., min_length=1, description="医院名称")
    invite_code: str = Field(..., min_length=1, description="邀请码")

